﻿using Sgr.Utilities;

namespace Sgr.Apis
{
    public static class TimesEndpoints
    {
        /// <summary>
        /// 注册系统时间相关 Minimal API 路由
        /// </summary>
        public static RouteGroupBuilder MapTimesEndpoints(this RouteGroupBuilder group)
        {
            group.MapGet("/utc", () =>
            {
                // 建议：使用标准 ISO 8601 格式（带 'T' 和 'Z'）
                return Results.Ok(DateTime.UtcNow.ToIso8601String());
            })
            .WithName("GetUtcNow")
            .Produces<string>(StatusCodes.Status200OK)
            .WithSummary("获取当前UTC时间")
            .WithDescription("返回标准 ISO 8601 格式的UTC时间字符串，例如：2025-11-07T10:30:45Z");

            group.MapGet("/timestamp", () =>
            {
                return Results.Ok(DateTimeHelper.TimestampSeconds());
            })
            .WithName("GetTimestamp")
            .Produces<long>(StatusCodes.Status200OK)
            .WithSummary("获取当前Unix时间戳（秒）")
            .WithDescription("返回从 1970-01-01 00:00:00 UTC 到当前时间的秒数（Unix timestamp）");

            group.MapGet("/timezone", () =>
            {
                var localTz = TimeZoneInfo.Local;
                return Results.Ok(new
                {
                    localTz.Id,
                    localTz.DisplayName,
                    localTz.BaseUtcOffset
                });
            })
            .WithName("GetTimeZone")
            .Produces<object>(StatusCodes.Status200OK)
            .WithSummary("获取系统时区信息")
            .WithDescription("返回时区ID、显示名称和基础UTC偏移量");

            return group;
        }
    }
}